<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改商品')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-product-edit" th:object="${product}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">货品编码：</label>
                <div class="col-sm-8">
                    <input name="proName" th:field="*{id}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">货品名称：</label>
                <div class="col-sm-8">
                    <input name="proName" th:field="*{proName}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">成本价格：</label>
                <div class="col-sm-8">
                    <input name="proCostprice" th:field="*{proCostprice}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">销售价格：</label>
                <div class="col-sm-8">
                    <input name="proSaleprice" th:field="*{proSaleprice}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">货品品牌：</label>
                <div class="col-sm-8">
                    <input name="brand" th:field="*{brand}" class="form-control" type="text">
                </div>
            </div>

            <div class = "form-group">
                <label class="col-sm-3 control-label">货品图片：</label>
                <div class="col-sm-8">
                    <input name="photo"  id="pic"  th:field="*{photo}" class="form-control" type="hidden">
                    <input type="file" id="photoPic">
                    <a id = "url"><img th:src="*{photo}" style="width: 90px;height: 90px"></a>
                </div>
            </div>

           <!-- <div class="form-group">
                <label class="col-sm-3 control-label">货品照片：</label>
                <div class="col-sm-8">
                    <input name="photo" th:field="*{photo}" class="form-control" type="text">
                </div>
            </div>-->
            <div class="form-group">    
                <label class="col-sm-3 control-label">货品信息：</label>
                <div class="col-sm-8">
                    <input name="info" th:field="*{info}" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "system/product";
        $("#form-product-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-product-edit').serialize());
            }
        }
        $("#photoPic").change(function () {
            var data = new FormData();
            data.append("file",$("#photoPic")[0].files[0]);
            $.ajax({
                type:"POST",
                url:ctx + "common/upload",
                data: data,
                cache:false,
                contentType:false,
                processData:false,
                dataType:'json',
                success:function (result) {
                    if (result.code == web_status.SUCCESS){
                        $("#url img").attr("src",result.fileName)
                        $("#pic").val(result.fileName)
                    }
                },
                error:function (error) {
                    alert("图片上传失败")
                }
            })
        })
    </script>
</body>
</html>